/*
Copyright (c) 2009, Joseph J. Bergeron
All rights reserved.

Redistribution  and  use  in  source  and  binary  forms,  with  or  without  
modification,  are  permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation 
     and/or other materials provided with the distribution.
    * Neither the name of the creators nor the names of its contributors
      may be used to endorse or promote products derived from this software 
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package hatkins.display
{
	import flash.display.Sprite;

	/**
	 * An abstract base class for compositing game scenes.
	 */
	public class HatkinsView extends Sprite
	{
		private var _cameraX:Number;
		private var _cameraY:Number;

		private var _shiftCoefX:Number;
		private var _shiftCoefY:Number;
		
		private var _viewportX:Number;
		private var _viewportY:Number;
		private var _viewportWidth:Number;
		private var _viewportHeight:Number;

		/**
		 * Create the view
		 */
		public function HatkinsView() {
			super();
			_cameraX = 0;
			_cameraY = 0;
			_shiftCoefX = 1;
			_shiftCoefY = 1;
			_viewportX = 0;
			_viewportY = 0;
			_viewportWidth = 0;
			_viewportHeight = 0;
		}
		
		/**
		 * Set the location and size of the viewport
		 */
		public function setViewport(viewportX:Number, viewportY:Number, viewportWidth:Number, viewportHeight:Number):void {
			_viewportX = viewportX;
			_viewportY = viewportY;
			_viewportWidth = viewportWidth;
			_viewportHeight = viewportHeight;
		}
		
		/**
		 * Get the viewport X position
		 */
		public function get viewportX():Number {
			return _viewportX;
		}
		
		/**
		 * Get the viewport Y position
		 */
		public function get viewportY():Number {
			return _viewportY;
		}
		
		/**
		 * Get the viewport width
		 */
		public function get viewportWidth():Number {
			return _viewportWidth;
		}
		
		/**
		 * Get the viewport height
		 */
		public function get viewportHeight():Number {
			return _viewportHeight;
		}
		
		/**
		 * Shift the camera position
		 */
		public function shiftCamera(shiftX:Number, shiftY:Number):void {
			_cameraX += _shiftCoefX * shiftX;
			_cameraY += _shiftCoefY * shiftY;
		}
		
		/**
		 * Place the camera position
		 */
		public function placeCamera(positionX:Number, positionY:Number):void {
			_cameraX = positionX;
			_cameraY = positionY;
		}

		/**
		 * Get or set the horizontal camera shift coeficient
		 */
		public function get cameraShiftXCoeficient():Number {
			return _shiftCoefX;
		}
		public function set cameraShiftXCoeficient(value:Number):void {
			_shiftCoefX = value;
		}

		/**
		 * Get or set the vertical camera shift coeficient
		 */
		public function get cameraShiftYCoeficient():Number {
			return _shiftCoefY;
		}
		public function set cameraShiftYCoeficient(value:Number):void {
			_shiftCoefY = value;
		}

		/**
		 * Get the camera X position
		 */
		public function get cameraX():Number {
			return _cameraX;
		}

		/**
		 * Get the camera Y position
		 */
		public function get cameraY():Number {
			return _cameraY;
		}
	}
}